<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html >
<head>
    <title>$!app_name</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<!-- 框架 -->
	<link href="${base}/include/css/default.css" rel="stylesheet" type="text/css"/>
	<script type='text/javascript'>
		var CONTEXTPATH = '${base}';
	</script>
    <script src="${base}/include/js/main.js"></script>
    <script src="${base}/include/js/string.js"></script>
	<!-- 分页  注意顺序 -->
	<link href="${base}/include/css/themes/gray/easyui.css" rel="stylesheet" type="text/css"/> 	
	<script src="${base}/include/js/jquery.easyui.min.js"></script>	
    <!-- 树 -->
    <script type="text/javascript" src="${base}/include/controls/ztree/jquery.ztree.core-3.5.min.js"></script> 
	<link rel="stylesheet" href="${base}/include/controls/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
    <SCRIPT type="text/javascript">
           <!--
           function add()
           {           
	        	var d = new Dialog("Add");
	           	d.Width = 420;
	           	d.Height = 330;
	           	d.Title = "新建";
	           	d.URL = "${base}/private/sys/task/toadd";
	           	d.onLoad = function(){

	           	};
	           	d.OKEvent = function(){
	           		if($DW.Verify.hasError()){
	          		  return;
	          	     }
	           		addSave();
	           	}; 
	           	d.show();
           }
           function addSave(){          		 
        		jQuery.ajax({
        			 	type: 'POST',
            			url : "${base}/private/sys/task/add" ,
            			data : $DW.$("#form1").serialize(),
            			success : function (res) { 
            				if(res=="true"){
            					$D.close();
            					Dialog.alert("添加成功！");
            					loadGrid();
            				}else{
            					Dialog.alert("添加失败！");
            				}
            				 
            				return false;
            			},
            			fail : function(res) {
            				Dialog.alert("系统错误?!");
            			}
                });
        	}
            function del() {
        	    var ids = [];
	       		var arr = $('#dg1').datagrid('getSelections');
	       	    if (!arr || arr.length == 0) {
	       	        Dialog.alert("请先选择要删除的配置项！");
	       	        return;
	       	    }
	       	    for(var i=0; i<arr.length; i++){
	       	        ids.push(arr[i].task_id);
	       	    }

		       	Dialog.confirm("确定删除？", function(){
		  	    	jQuery.ajax({
		  	    	 	type: 'POST',
		  	    		url : "${base}/private/sys/task/deleteIds?ids="+ids ,
		  	    		success : function (res) { 
		  	    			if(res=="true"){    				
		  	    				Dialog.alert("删除成功！");
		  	    				loadGrid();
		  	    			}else{
		  	    				Dialog.alert("删除失败！");
		  	    			}			 
		  	    			return false;
		  	    		},
		  	    		fail : function(res) {
		  	    			Dialog.alert("系统错误!");
		  	    		}
		  	    	});
		  	    }, "", 250, 150);    
           }
           function update()
           {
        	    var arr = $('#dg1').datagrid('getSelected');
                if (!arr || arr.length == 0) {
                   Dialog.alert("请先选择要编辑的项！");
                   return;
                }
	        	var d = new Dialog("Update");
	           	d.Width = 420;
	           	d.Height = 330;
	           	d.Title = "修改";
	           	d.URL = "${base}/private/sys/task/toupdate?task_id="+arr.task_id;
	           	d.onLoad = function(){
	           	};
	           	d.OKEvent = function(){

	           		updateSave();
	           	};
	           	d.show();
           }
           function updateId(id)
           {        
	        	var d = new Dialog("Update");
	           	d.Width = 420;
	           	d.Height = 330;
	           	d.Title = "修改";
	           	d.URL = "${base}/private/sys/task/toupdate?task_id="+id;
	           	d.onLoad = function(){
	           	};
	           	d.OKEvent = function(){
	           		updateSave();
	           	};
	           	d.show();
           }
           function updateSave(){ 
		   
       		    if($DW.Verify.hasError()){
       		       return;
       	        } 
				 
       		    jQuery.ajax({
       				type: 'POST',
           			url : "${base}/private/sys/task/update" ,
           			data : $DW.$("#form1").serialize(),
           			success : function (res) { 
           				
           				if(res=="true"){
           					$D.close();
           					Dialog.alert("修改成功！");
           					loadGrid();
           				}else{
           					Dialog.alert("修改失败！");
           				}
           				 
           				return false;
           			},
           			fail : function(res) {
           				Dialog.alert("系统错误?!");
           			}
           		});
       	   } 
           function getWidth(percent){
        	   return document.body.clientWidth*percent;
		   }
           function loadGrid(){
        	   $("#dg1").datagrid({  
        	        width:"auto",
        	   		height:"auto",
        	        nowrap: false,  
        	        striped: true,  
        	        border: true,  
        	        collapsible:false,//是否可折叠的  
        	        fit: false,//自动大小  
        	        url:"${base}/private/sys/task/list",
        	        //sortName: 'code',  
        	        //sortOrder: 'desc',  
        	        remoteSort:false,   
        	        idField:"task_id",
        	        singleSelect:false,//是否单选  
        	        pagination:true,//分页控件  
        	        rownumbers:true,//行号  
        	        fitColumns: true,//行自适应
					pageSize: 10,
        	        pageList:[5,10,15,20,30,40,50],
        	        loadMsg:'数据加载中...',
        	        columns:[[
						{title : 'ID',field : 'task_id',width:getWidth(0.06),align : 'left'},
                        {title : '任务名称',field : 'task_name',width:getWidth(0.12),align : 'left'},
                        {title : '状态',field : 'is_enable',width:getWidth(0.08),align : 'left',
                            formatter: function(value,row,index){
                                var str="";
                                if(row.is_enable==0){
                                    str="启用";
                                }else str="禁用";
                                return str;
                            }
                        },
                        {title : '操作',field : 'cz',width:getWidth(0.08),align : 'left',
                            formatter:function(value,obj,index){
                                return "<a href='javascript:updateId("+obj.task_id+")'>查看详情</a>";

                            }
                        }
        	        ]],
        	        frozenColumns:[[  
        	            {field:"id",checkbox:true}
        	        ]],
        	        onDblClickRow:function(rowIndex,row)
        	        {
        	        	updateId(row.task_id);
        	        }
        	    });  
        	    //设置分页控件  
        	    var p = $("#dg1").datagrid("getPager");  
        	    $(p).pagination({  
        	        beforePageText: "第",//页数文本框前显示的汉字  
        	        afterPageText: "页    共 {pages} 页",  
        	        displayMsg: "当前显示 {from} - {to} 条记录   共 {total} 条记录",  
        	        onBeforeRefresh:function(){ 
        	        } 
        	    });  
           }
           function initButton(){
               Page.initBtn();
               $!initBtn
           }
           Page.onLoad(function() {
               loadGrid();
               initButton();
           });
           $(window).resize(function () {
       		clearTimeout(timer);
       		timer=setTimeout(function(){
       		  $('#dg1').datagrid('resize');
       		  $('div.panel-body').css('width','auto'); 
       		 },200);
       		});
           //-->
       </SCRIPT>
</head>
<body leftmargin="0" topmargin="0"
	style="overflow-x: hidden; overflow-y: auto">
<table width="100%" border="0" cellspacing="6" cellpadding="0"
		style="border-collapse: separate; border-spacing: 6px;">
		<tr valign="top">
			<td width="100%">
	<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border-collapse: separate; border-spacing: 0;">
    <tr valign="top">
      <td>
	   <form name="form1" id="form1" method="post" > 
        <input type="hidden" name="checkids" id="checkids" value="">
                                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="blockTable">
                                      <tr>
                                        <td class="blockTd">
                                        
                                        <table width="100%" border="0" cellspacing="0" cellpadding="6" >
                                          <tr>
                                            <td valign="middle"><img src="${base}/images/icons/icon021a1.gif" width="20" height="20" />
                                            &nbsp;<span>定时任务</span></td>
                                          </tr>
                                          <tr>
                                            <tr>
												<td style="padding: 0 8px 4px;"><a
													href='javascript:void(0);' ztype='zPushBtn'
													class='zPushBtn' hidefocus='true' tabindex='-1'
													onselectstart='return false' id='BtnAdd' onClick="add();"><img
														src="${base}/images/icons/icon022a2.gif"
														width="20" height="20" /><b>新建&nbsp;</b></a> <a
													href='javascript:void(0);' ztype='zPushBtn'
													class='zPushBtn' hidefocus='true' tabindex='-1'
													onselectstart='return false' id='BtnUpdate'
													onClick="update();"><img
														src="${base}/images/icons/icon022a4.gif"
														width="20" height="20" /><b>编辑&nbsp;</b></a> <a
													href='javascript:void(0);' ztype='zPushBtn'
													class='zPushBtn' hidefocus='true' tabindex='-1'
													onselectstart='return false' id='BtnDel' onClick="del();"><img
														src="${base}/images/icons/icon022a3.gif"
														width="20" height="20" /><b>删除&nbsp;</b></a>  </td>
											</tr>
                                          </tr>
                                          <tr>
                                            <td style="padding:0px 5px;">                                             
                                            <table width="100%" height="100%" id="dg1" size="10" cellpadding="2" cellspacing="0">
												<tr><td></td></tr>
											</table>                                          
                                            </td>
                                          </tr>
                                        </table></td>
                                      </tr>
                                    </table>
                                    
	   </form>
	  </td>
    </tr>
 </table>
 </td>
    </tr>
 </table>
</body>
</html>
